<template>
  <div style="margin-top: 50px">
    <el-form ref="activityInfoForm" :model="value" :rules="rules" label-width="120px" style="width: 600px" size="small">
      <el-form-item label="项目名称" prop="projectName">
        <el-input v-model="value.projectName" />
      </el-form-item>
      <el-form-item label="预算金额" prop="amount">
        <el-input-number v-model="value.amount" controls-position="right" :min="0" />
      </el-form-item>
      <el-form-item label="客单金额" prop="singleMaxAmount">
        <el-input-number v-model="value.singleMaxAmount" controls-position="right" :min="0" />
      </el-form-item>
      <el-form-item label="折扣" prop="purchRate">
        <el-input-number v-model="value.purchRate" controls-position="right" :min="1" placeholder="例如：85 既85折" />
      </el-form-item>
      <el-form-item style="text-align: center">
        <el-button type="primary" size="medium" @click="handleNext('activityInfoForm')">下一步，填写商品属性</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'ActivityInfoDetail',
  props: {
    value: Object,
    isEdit: { type: Boolean, default: false }
  },
  data() {
    return {
      hasEditCreated: false,
      rules: {
        projectName: [
          { required: true, message: '请输入活动名', trigger: 'blur' }
        ],
        amount: [
          { required: true, message: '请输入预算金额', trigger: 'blur' }
        ],
        singleMaxAmount: [
          { required: true, message: '请输入客单金额', trigger: 'blur' }
        ],
        settlementCycle: [
          { required: true, message: '请输入结算周期', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    // 商品的编号
    productId() {
      return this.value.id
    }
  },
  watch: {
    productId: function(newValue) {
      if (!this.isEdit) return
      if (this.hasEditCreated) return
      if (newValue === undefined || newValue == null || newValue === 0) return
      this.handleEditCreated()
    }
  },
  created() {

  },
  methods: {
    // 处理编辑逻辑
    handleEditCreated() {
      this.hasEditCreated = true
    },
    handleNext(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('nextStep')
        } else {
          this.$message({ message: '验证失败', type: 'error', duration: 1000 })
          return false
        }
      })
    }
  }
}
</script>

<style scoped>
</style>
